import { createStore } from 'vuex'
import {Session} from '@/utils/storage'

export default createStore({
  state: {
    routes: [], // 用来存储动态路由的数据
  },
  getters: {
    
    // 获取存储的路由数据
    routes: (state) => state.routes
  },
  mutations: {
    // 用来更新路由数据
    setRoutes(state, routes) {
      state.routes = routes;
    }
  },
  actions: {
     // 异步获取路由数据并提交 mutation
    async fetchRoutes({ commit }) {
      try {
        const response = await fetch('/api/getRoutes'); // 替换为实际的 API 地址
        const data = await response.json();
        commit('setRoutes', data);
      } catch (error) {
        console.error('获取路由数据失败:', error);
      }
    }
  },
  modules: {
  }
})
